package com.aboo.web.common.util;

import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator;
import org.springframework.util.ClassUtils;

public class InfrastructureAdvisorAutoProxyCreatorExt extends InfrastructureAdvisorAutoProxyCreator{
	private static final long serialVersionUID = -2181245875469682969L;
	private ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader();

	protected Object createProxy(Class<?> beanClass, String beanName,
			Object[] specificInterceptors, TargetSource targetSource) {
		boolean proxyTargetClass = this.isProxyTargetClass();
		try {
			Class<?>[] targetInterfaces = ClassUtils.getAllInterfacesForClass(
					beanClass, this.proxyClassLoader);
			if (targetInterfaces != null && targetInterfaces.length != 0) {
				this.setProxyTargetClass(false);
			}
			return super.createProxy(beanClass, beanName, specificInterceptors,
					targetSource);
		} finally {
			this.setProxyTargetClass(proxyTargetClass);
		}
	}
}
